package com.company.OfferGuide;

/**
 * @author jrue
 * @version 1.0
 * @date 2020/3/24 9:39
 */
public class 按摩师 {

    public int massage(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        if (nums.length == 1) return nums[0];
        if (nums.length == 2) return Math.max(nums[0],nums[1]);

        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0],nums[1]);

        for (int i = 2; i < dp.length; i++) {
            dp[i] = Math.max(dp[i - 1], nums[i] + dp[i - 2]);
        }

        int max = dp[0];

        for (int i = 1; i < dp.length; i++) {
            max = Math.max(max,dp[i]);
        }

        return max;
    }

}
